package com.example.module_main

import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.lib_common.BaseApplication
import com.example.lib_common.mmkv.AppMMKV
import com.example.lib_common.router.service.TestService
import com.example.lib_myrouter.Router
import com.example.lib_storage.database.DBUtils
import com.example.lib_storage.database.entity.HistoryEntity

@Route(path = "/main/SplashActivity")
class SplashActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_splash)
        //判断是否同意：
        if (!AppMMKV.splashAgreement) {
           //弹出对话框提示用户同意，用户同意后再进行初始化bugly、友盟
            Thread.sleep(2000)
            AppMMKV.splashAgreement = true
            BaseApplication.instance.initBugly()
            BaseApplication.instance.initUmeng()

        }
        //访问live模块类：ARouter的IProvider
        val testService:TestService = ARouter.getInstance().build("/live/TestService").navigation() as TestService
        val result = testService.test("yaotianxue")
        Toast.makeText(this,"调用live模块的服务得到结果 $result",Toast.LENGTH_SHORT).show()
        //测试room数据库
        DBUtils.getDB().historyDao().insertAll(HistoryEntity(1,1,"1","1","1","1","1"),HistoryEntity(2,2,"2","2","2","2","2"))
        Log.d("room", "查询数据: ${DBUtils.getDB().historyDao().getAll()}")
        DBUtils.getDB().historyDao().delete(HistoryEntity(1,1,"1","1","1","1","1"))
        Log.d("room", "查询数据: ${DBUtils.getDB().historyDao().getAll()}")
    }

    /**
     * 测试自己封装的Router
     */
    fun toLive(view: View) {
//        Router.getInstance().navigation(this,"/live/LiveActivity")
        ARouter.getInstance().build("/live/LiveActivity").navigation()
    }
}